package com.wwwarehouse.financialcenter.fragment.moneywarehouse.bankcard;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;

import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.financialcenter.R;
import com.wwwarehouse.financialcenter.adapter.moneyhouse.BankBranchAdapter;
import com.wwwarehouse.financialcenter.bean.bindingcard.BankInfoBean;
import com.wwwarehouse.financialcenter.fragment.base.TheParentFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 * Copyright  : Copyright (c) 2017
 * Author     : yfwang
 * Date       : 2017/11/14 20:16
 */
public class BankBranchListFragment extends TheParentFragment {
    private RecyclerView mRecyclerView;
    private int mHeight;
    private List<BankInfoBean.DataBean> mList;

    @Override
    protected int getContentId() {
        return R.layout.financial_center_fragment_bindcard_list;
    }
    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        return null;
    }
    @Override
    protected void init(View view) {
        Bundle bundle = getArguments();

        mList = new ArrayList<>();
        if (bundle != null) {
            List<BankInfoBean.DataBean> data = (List<BankInfoBean.DataBean>) bundle.getSerializable("data");
            int pos = bundle.getInt("pos") - 1;
            int num = bundle.getInt("num");
            for (int i = pos * num; i < num + pos * num; i++) {
                if (i >= 0 && i < data.size()) {
                    mList.add(data.get(i));
                }
            }
        }
        mRecyclerView = findView(view, R.id.rv_content);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity) {
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }

            @Override
            public boolean canScrollVertically() {
                return false;
            }

        });
        final ViewTreeObserver observer = mRecyclerView.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                observer.removeGlobalOnLayoutListener(this);
                mHeight = mRecyclerView.getHeight();
                BankBranchAdapter bankBranchAdapter = new BankBranchAdapter(mActivity, mList, mHeight);
                mRecyclerView.setAdapter(bankBranchAdapter);
            }
        });


    }

    @Override
    public void onSuccess(CommonClass commonClass, int what) {

    }

    @Override
    public void onReLoad(int code) {

    }
}
